<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="some-id"></div>
  </body>
  <script>
    // MutationObserver 是微任务，监听dom树的变化
    var target = document.querySelector("#some-id");
    setTimeout(() => {
      target.innerHTML = "9090";
    }, 3000);
    var observer = new MutationObserver(function (mutations) {
      mutations.forEach(function (mutation) {
        console.log(mutations);
        console.log(mutation.type);
      });
    });
    var config = { attributes: true, childList: true, characterData: true };
    observer.observe(target, config);
    observer.disconnect(); //阻止 MutationObserver 实例继续接收的通知

    var person = {};
    Object.observe(person, function (arr) {
      // 已被废弃，执行报错
      var change = arr[0];
      console.log(change.type, change.name, change.oldValue);
    });
  </script>
</html>
